#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "case.h"

#include <QMessageBox>
#include <QDebug>
#include <QResizeEvent>
#include <QCloseEvent>
#include <QRandomGenerator>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // case: 去边框+窗口透明
    setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
    // case: 窗口最大化
    showMaximized();

    for(int i = 0; i < 10; ++i) // 循环创建Case对象
    {
        Case* c = new Case(this); // 指定父对象，则图片在主窗口显示
        //c->move((width() - c->width()) / 2, (height() - c->height()) / 2);
        c->move(QRandomGenerator::global()->bounded(this->width()),
                QRandomGenerator::global()->bounded(this->height()));

        c->show();
    }

    //    connect(ui->button, &Mybutton::clicked, this, [=]() // 点击Mybutton后弹窗
//    {
//       QMessageBox::information(this, "点击", "emm...");
//    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::closeEvent(QCloseEvent *eve)
{
    int ret = QMessageBox::question(this, "注意！", "是否确定关闭窗口");
    if(ret == QMessageBox::Yes){
        eve->accept();
    }else{
        eve->ignore();
    }
}

void MainWindow::resizeEvent(QResizeEvent *eve)
{
    qDebug() << "oldSize: " << eve->oldSize() << "currentSize" << eve->size();
}



